package com.mikao.service.impl;

import com.mikao.dao.TypeDao;
import com.mikao.dto.bo.ReqDataTableDto;
import com.mikao.dto.bo.TypeForm;
import com.mikao.dto.vo.RspDataTableDto;
import com.mikao.entity.Type;
import com.mikao.service.TypeService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author kenny
 */

@Service
public class TypeServiceImpl implements TypeService {

    private TypeDao typeDao;

    public TypeServiceImpl(TypeDao typeDao) {
        this.typeDao = typeDao;
    }

    @Override
    public RspDataTableDto<Type> typeList(ReqDataTableDto dataTableDTO) {
        List<Type> all = typeDao.findAll();
        return new RspDataTableDto<>(dataTableDTO.getDraw(), (long) all.size(), all);
    }

    @Override
    public void addType(TypeForm typeForm) {
        Type type = new Type();
        type.setName(typeForm.getName());
        typeDao.saveAndFlush(type);
    }

    @Override
    public void deleteType(Long id) {
        typeDao.delete(id);
    }

    @Override
    public List<Type> getTypeList() {
        return typeDao.findAll();
    }

}
